package leetcode.code0179;

import java.util.Arrays;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution implements IDebug {

	public String largestNumber(int[] nums) {
		Integer[] n = new Integer[nums.length];
		for (int i = 0; i < nums.length; i++) {
			n[i] = nums[i];
		}
		Arrays.sort(n, (a, b) -> {
			int ap = 10, bp = 10;
			while (ap <= a) {
				ap *= 10;
			}
			while (bp <= b) {
				bp *= 10;
			}
			return (b * ap + a) - (a * bp + b);
		});
		if (n[0] == 0) {
			return "0";
		}
		StringBuffer ans = new StringBuffer();
		for (int num : n) {
			ans.append(num);
		}
		return ans.toString();
	}

	@Override
	public void debug1() {
		HelpDebug.compare("9534330", this.largestNumber(HelpDebug.str2array3("[3,30,34,5,9]")));

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();
	}

}
